<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.4.1.js"></script>
</head>
<body>
<div style="width: 100px;height: 100px;background-color: red;position: absolute;top: 0;left: 0;"></div>
</body>
<script>
    let $div = $("div");
    $div.mousedown(function (e) {
        let even = e || event;
        let startX = even.clientX-$(this).offset().left;
        let startY = even.clientY-$(this).offset().top;
        $(document).mousemove(function (e) {
            let even = e || event;
            let moveX = even.clientX-startX;
            let moveY = even.clientY-startY;
            $div.offset({"top":moveY,"left":moveX});
        });
        $div.mouseup(function (){
            $(document).unbind("mousemove");
            $div.unbind("mouseup");
        })
    });
</script>
</html>